package cn.ym.ymcc.web.controller;


import cn.ym.ymcc.doc.CourseDoc;
import cn.ym.ymcc.query.ESQuery;
import cn.ym.ymcc.result.JSONResult;
import cn.ym.ymcc.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    /**
     * 保存课程到es里面
     * @param courseDoc
     * @return
     */
    @PostMapping("/save")
    public JSONResult save(@RequestBody CourseDoc courseDoc){
        //保存课程文档
        searchService.save(courseDoc);
        return JSONResult.success();
    }

    /**
     * es查询列表
     * @param esQuery
     * @return
     */
    @PostMapping("/search")
    public JSONResult search(@RequestBody ESQuery esQuery){

        return JSONResult.success(searchService.search(esQuery));
    }


}
